//whole.js
//获取应用实例
const app = getApp()

Page({
  data: {
    wholeItems: [],
    imgDomain: app.data.imgDomain,
    windowHeight: 0,
    housing_types: {
      1: '小区住宅',
      2: '公寓'
    },
    room_type: {
      1: '押一付一',
      2: '押一付二',
      3: '押一付三',
      4: '押二付一',
      5: '押二付二',
      6: '押二付三',
      7: '半年付',
      8: '年付'
    },
    page: 1,
    size: 6,
    loaded: false
  },
  //事件处理函数
  bindViewTap: function () {
  },
  onLoad: function () {
    wx.getSystemInfo ({
      success: (res) => {
        console.log(res)
        this.setData({windowHeight: res.windowHeight})
      }
    })
    this.getWholeItems()
  },
  /**
   * 加载更多
   */
  loadMore(e) {
    this.getWholeItems ()
  },
  /**
   * @purpose 获取整租房源列表
   */
  getWholeItems() {
    if (this.data.loaded) {
      return false
    }
    wx.showLoading()
    let data = {
      page: this.data.page,
      size: this.data.size
    }
    app.request('get', 'wholeItems', data, (r) => {
      if (r.length < this.data.size) {
        this.setData({loaded: true})
      } else {
        this.setData({page: this.data.page + 1})
      }
      let data = this.data.wholeItems.concat(r)
      this.setData({ wholeItems: data })
    })
  },
  jump: function (event) {
    if (!event.currentTarget.dataset.jumpUrl) {
      return false;
    }
    wx.navigateTo({
      url: event.currentTarget.dataset.jumpUrl
    })
  }
})
